<?php

require_once( '../system/smarty.inc' );

require_once( '../system/mdao/Class_D_DNPW_AREA.php' );
require_once( '../system/mdao/Class_M_OTHER.php' );

require_once( '../system/Class_ERROR.php' );
require_once( '../system/login.inc.php' );
require_once( '../system/aoki_m.php' );
require_once( '../system/Class_PWD.php' );

Class_PWD::valid_auth(AOKI_AUTH_DNP_AREA, $login['staff_auth']);


//$pattern = Class_M_OTHER::get_pattern_array(PLEASE_SELECT_ARR, 23, true);
$patternd = Class_M_OTHER::get_pattern_array(PLEASE_SELECT_ARR, 23,TRUE);
$pattern      = $patternd["pattern"];
$patternsort  = $patternd["sort"];
	
$now_pattern_sort = 0;

//$dists   = Class_M_OTHER::get_dist_array();

$forms = $_GET;

//---CSVダウンロード　処理開始
if ( isset( $forms['mode'] ) &&  (  $forms['mode'] == "update" ) ){
	$dao = new Class_D_DNPW_AREA;
	$dao -> setTableNameWeek($forms['matrix_cd']);
	
	if ( isset( $forms['pattern_cd'] ) &&  ( !empty( $forms['pattern_cd'] ) ) ){
		//$wherearr[] = sprintf(" a.pattern_cd =  '%s' ",$forms['pattern_cd'] );
		$now_pattern_sort = $patternsort[$forms['pattern_cd']];
		if ($now_pattern_sort == '3') {
			if ($dao->insertinto($forms['pattern_cd'], $now_pattern_sort)){
				$mesg = "<p class='error'>DNPエリア情報を更新成功しました</p>";
			}else{
				$mesg = "<p class='error'>DNPエリア情報を更新失敗しました</p>";
			}
		}else {
			if ($dao->insertinto($forms['pattern_cd'],  $now_pattern_sort)){
				$mesg = "<p class='error'>DNPエリア情報を更新成功しました</p>";
			}else{
				$mesg = "<p class='error'>DNPエリア情報を更新失敗しました</p>";
			}
		}
	}else {
		
	}
}

if (empty($forms["year4"])) {
	$forms["year4"] = date('Y');
}


if( isset($forms) ) $smarty->assign('forms', $forms);
if( isset($data) )  $smarty->assign('data', $data);
if( isset($mesg) )  $smarty->assign('mesg', $mesg);


$smarty->assign('year4',  Class_PWD::get_years());
$week= Class_M_OTHER::get_week_array( $forms["year4"], PLEASE_SELECT_ARR );
$smarty->assign('week', $week );
$smarty->assign('pattern', $pattern );


$smarty->assign('menu', $smarty->fetch('menu.html') );
$smarty->assign('logout', $smarty->fetch('logout.html') );
$smarty->assign('footer', $smarty->fetch('footer.html') );
$smarty->display('ddnpwarea_update.html');
?>